package com.etoak.controller;

import com.etoak.common.utils.uuid.IdUtils;
import com.etoak.entity.ProductLine;
import com.etoak.service.IProductlineService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Checklist库产品线controller
 *
 * @author zhixuebin
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/goertek/checklist/productLine")
public class ProductLineController extends BaseController {

    @Autowired
    IProductlineService productlineService;

    /**
     * 添加产品线
     * @param productline
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addProductLine(@RequestBody ProductLine productline){
        //验重
        List<ProductLine> search = productlineService.getProductLine(productline);
        if(StringUtils.isNull(search) || search.size() < 1){
            //设置主键
            String id = IdUtils.simpleUUID();
            productline.setId(id);
            productlineService.add(productline);
        }
        return AjaxResult.success("产品线添加成功");
    }

    /**
     * 根据领域id查询产品线
     * @param territoryId
     * @return
     */
    @GetMapping("/getProductLineByTerritory")
    public AjaxResult getProductLineByTerritory(@RequestParam String territoryId){
        List<ProductLine> productlineList = productlineService.getProductLineByTerritory(territoryId);
        return AjaxResult.success(productlineList);
    }

}
